#include "user_server.hpp"
#include <gflags/gflags.h>

DEFINE_bool(log_mode, false, "运行模式： true-发布模式； false-测试模式");
DEFINE_string(log_file, "", "发布模式日志更新地址");
DEFINE_int32(log_level, 1, "默认日志等级");

DEFINE_string(etcd_host, "127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(registry_instance_name, "/user_service/instance", "当前实例名称");
DEFINE_string(access_host, "47.107.92.191:10010", "当前实例的外部访问地址");

DEFINE_int32(rpc_linsten_port, 10010, "RPC服务器监听端口号");
DEFINE_int32(rpc_idle_timeout_sec, 10, "这是RPC服务器的等待时长");
DEFINE_int32(rpc_num_threads, 5, "这是RPC服务器IO的线程数");

DEFINE_string(discovery_instance_service, "/service/file_service", "服务发现监控根目录");

DEFINE_string(dms_key_id, "LTAI5tAiPrp8xriXXAUmzGE5", "这是dms平台访问密钥ID");
DEFINE_string(dms_Key_secret, "1sr9HfOxGubXxODuP91PTxHIZNjEyV", "这是dms平台访问密钥");

DEFINE_string(es_host, "http://120.76.98.215:9200/", "这是ES服务器的地址");

DEFINE_string(mysql_host, "120.76.98.215", "这是MySQL服务器的地址");
DEFINE_int32(mysql_port, 1314, "这是MySQL服务器的默认端口号");
DEFINE_int32(mysql_max_pool, 3, "这是MySQL连接池的最大连接数");
DEFINE_string(mysql_user, "zhiang_root", "这是登录用户名");
DEFINE_string(mysql_password, "123456Aa.", "这是登录用户密码");
DEFINE_string(mysql_db, "chatSystem", "这是数据库的库");
DEFINE_string(mysql_charset, "utf8", "这是数据库访问的编码格式");

DEFINE_string(redis_host, "120.76.98.215", "这是redis的IP地址");
DEFINE_int32(redis_port, 14514, "这是redis服务器的端口号");
DEFINE_bool(redis_keep_alive, true, "是否使用保活长连接机制");
DEFINE_int32(redis_db, 0, "redis的库的编号, 默认0");

int main(int argc, char* argv[]) 
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    init_logger(FLAGS_log_mode, FLAGS_log_file, FLAGS_log_level);
    zhiang::UserBuilder user_builder;
    user_builder.make_es_client({FLAGS_es_host});
    user_builder.make_mysql_client(FLAGS_mysql_user, FLAGS_mysql_password, FLAGS_mysql_db,
         FLAGS_mysql_host, FLAGS_mysql_port, FLAGS_mysql_charset, FLAGS_mysql_max_pool);
    user_builder.make_redis_client(FLAGS_redis_host, FLAGS_redis_port, FLAGS_redis_db, FLAGS_redis_keep_alive);
    user_builder.make_dms_client(FLAGS_dms_key_id, FLAGS_dms_Key_secret);
    user_builder.make_discovery_client(FLAGS_etcd_host, FLAGS_base_service, FLAGS_discovery_instance_service);
    user_builder.make_rpc_server(FLAGS_rpc_linsten_port, FLAGS_rpc_idle_timeout_sec, FLAGS_rpc_num_threads);
    user_builder.make_registry_client(FLAGS_etcd_host, FLAGS_base_service + FLAGS_registry_instance_name, FLAGS_access_host);
    auto user_server = user_builder.build();
    user_server->start();
    return 0;
}